<?php 
namespace Home\Model;
use Think\Model;
/*
	上传素材
*/
class UploadMaterialModel extends Model {
	
	protected $tableName = 'user_upload_material'; 
	
	//添加
	public function upload_material_add($data){
		$rc = M('UserUploadMaterial')->add($data);
		return $rc;
	}
	
	
	//修改
	public function upload_material_save($id,$data){
		$rc = M('UserUploadMaterial')->where('id = %d',$id)->save($data);
		return $rc;
	}
	
	//删除
	public function upload_material_delete($id){
		$rc = M('UserUploadMaterial')->where('id = %d',$id)->save(array('is_pass'=>'-2'));
		return $rc;
	}
	
	
	
	//查询单条
	public function upload_material_find($id){
		$rc = M('UserUploadMaterial')->where('id = %d and is_pass != -2',$id)->find();
		return $rc;
	}
	
	//多条
	public function upload_material_list($uid,$limit='0,10'){
		$rc = M('UserUploadMaterial')->where('uid = %d and is_pass != -2',$uid)
									 ->limit($limit)
									 ->order('id desc')
									 ->field('id,title,type,uid,upload_address,is_pass,upload_link')
									 ->select();
		return $rc;
	}
	
	//查询素材的全部
	public function upload_material_all(){
		$rc = M('Video')->where('status = 1')
					    ->order('id desc')
					    ->field('id,title,upload_link,video_picture')
					    ->select();
		return $rc;
		
	}
	
	//搜寻标题
	public function upload_material_search($where){
		$rc = M('Video')->where('status = 1 '.$where.'')
					    ->order('id desc')
					    ->field('id,title,upload_link,video_picture')
					    ->select();
		return $rc;
		
	}
	
	//搜寻标题
	public function upload_material_category($cid){
		$rc = M('Video')->alias('v')
						->join('__VIDEO_CLASSIFY__ as vc on v.cid = vc.id')
						->where('v.status = 1 and  vc.status = 1 and vc.id = %d',$cid)
					    ->order('v.id desc')
					    ->field('v.id,v.title,v.upload_link,v.video_picture')
					    ->select();
		return $rc;
		
	}
	
	
}
